package com.minis.beans.factory.xml;

import com.minis.beans.config.BeanDefinition;
import com.minis.beans.factory.SimpleBeanFactory;
import com.minis.core.Resource;
import org.dom4j.Element;

/**
 * @author chao
 */
public class XmlBeanDefinitionReader {
    SimpleBeanFactory simpleBeanFactory;

    public XmlBeanDefinitionReader(SimpleBeanFactory simpleBeanFactory){
        this.simpleBeanFactory = simpleBeanFactory;
    }

    public void loadBeanDefinitions(Resource resource){
        while (resource.hasNext()){
            Element element = (Element) resource.next();
            String beanId = element.attributeValue("id");
            String beanClassName = element.attributeValue("class");
            BeanDefinition beanDefinition = new BeanDefinition(beanId,beanClassName);
            this.simpleBeanFactory.registerBean(beanId,beanClassName);
        }
    }
}
